import { init, h, styleModule, eventListenersModule, toVNode } from 'snabbdom'

// 注册模块，模块用来扩展h函数的功能
const patch = init([
  styleModule,
  eventListenersModule
])

// 创建vnode
let vnode = h('div#container', [
  h('h1', 'hello snabbdom'),
  h('p', '段落')
])

// 挂载vnode
const app = document.querySelector('#app')
console.log(toVNode('<span>fsd<span>'))
let oldVnode = patch(app, vnode)
console.log(oldVnode)

setTimeout(() => {
  let vnode = h('div#container', [
    h('h1', { style: { backgroundColor: 'red' } }, 'hello world'),
    h('p', { on: { click: handleClick } }, 'parg')
  ])
  patch(oldVnode, vnode)
  console.log(vnode)
}, 1500)

function handleClick () {
  alert('hh')
}